package repositories;

import java.util.Collection;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import domain.Project;

@Repository
public interface ProjectRepository extends JpaRepository<Project, Integer> {

	@Query("select p from Project p where p.status!='Finished' and p.status!='Creating'")
	Collection<Project> findNotFinishedProjects ();
	
	@Query("select distinct p from Project p join p.vacancies v where v.userGroup.id = ?1 and v.peopleRequired > 0 and p.status!='Creating'")
	Collection<Project> findAvailableProjectsForGroup(int userGroupId);
	
	@Query("select p from Project p join p.registrations r where r.user.id = ?1 and p.status!='Creating'")
	Collection<Project> findJoinedProjects(int userId);
	
	@Query("select p from Project p where p.creator.id = ?1")
	Collection<Project> findCreatedProjects(int userId);
	
	@Query("select p from Project p join p.followers f where f.id = ?1")
	Collection<Project> findFollowedProjects(int userId);
}
